# 118. 杨辉三角

var generate = function(numRows) {
  const resArr = []
  let index = 0
  while (index++ < numRows) {
    const res = []
    const prev = resArr[index - 2] || []
    for (let i = 0; i < index; i++) {
      const left = prev[i - 1] || 0
      const right = prev[i] || 0
      res.push(Math.max(1, left + right))
    }
    resArr.push(res)
  }

  return resArr
}
console.log(generate(5))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Last Updated: 6/27/2023, 7:40:45 PM